//
//  MBForumShowCommentViewController.m
//  MiBaoTu
//
//  Created by admin on 16/10/19.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBForumShowCommentViewController.h"

@interface MBForumShowCommentViewController () {
    UIScrollView            *_scrollView;
    UILabel                 *_showContentLb;
}

@end
@implementation MBForumShowCommentViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    [self setNavBar];
    
    [self onCreateUI];
}

- (void)setNavBar
{
    [self setTitleView:_titleStr];
    [self setBackItem];
}

- (void)onCreateUI
{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(25*PERCEN, 25*PERCEN, SCREEN_WIDTH-2*25*PERCEN, self.view.height-25*PERCEN)];

    _scrollView.backgroundColor = [UIColor clearColor];
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    _showContentLb = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, _scrollView.width, _scrollView.height)];
    if (ISIPAD) {
        _showContentLb.frame=CGRectMake(460*PERCEN, 30*PERCEN, SCREEN_WIDTH-2*460*PERCEN, SCREEN_HEIGHT-30*PERCEN);
    }
    _showContentLb.backgroundColor = [UIColor clearColor];

    _showContentLb.text = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"Content"]];

    _showContentLb.textAlignment = NSTextAlignmentLeft;
    _showContentLb.font = [UIFont systemFontOfSize:13.];
    
    _showContentLb.numberOfLines = 0;
    [_scrollView addSubview:_showContentLb];
    float height;
    if (ISIPAD) {
          _showContentLb.textAlignment = NSTextAlignmentLeft;
         _showContentLb.font = [UIFont systemFontOfSize:28*PERCEN];
        NSMutableParagraphStyle *mutStyle = [[NSMutableParagraphStyle alloc]init];
        mutStyle.lineSpacing = 14*PERCEN;
        NSMutableAttributedString *mutAttribute = [[NSMutableAttributedString alloc]initWithString:_showContentLb.text];
        [mutAttribute addAttribute:NSFontAttributeName value:_showContentLb.font range:NSMakeRange(0, _showContentLb.text.length)];
        [mutAttribute addAttribute:NSParagraphStyleAttributeName value:mutStyle range:NSMakeRange(0, _showContentLb.text.length)];
        height = [mutAttribute boundingRectWithSize:CGSizeMake(_showContentLb.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height+10;
        _showContentLb.height = height;
        _showContentLb.attributedText = mutAttribute;
           _scrollView.contentSize = CGSizeMake(_scrollView.width, (_scrollView.height > height ? _scrollView.height:height));

    }else{
          height = [_showContentLb.text boundingRectWithSize:CGSizeMake(_scrollView.width, 1000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:_showContentLb.font} context:nil].size.height;
        
        _showContentLb.height = height;
        _scrollView.contentSize = CGSizeMake(_scrollView.width, (_scrollView.height > height ? _scrollView.height:height));

    }
 
    
    
    if (_scrollView.height > height) {
        _scrollView.scrollEnabled = NO;
    } else {
        _scrollView.scrollEnabled = YES;
    }
}

@end
